package com.baiyang.server.service.system.impl;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baiyang.server.dao.system.JurisdictionInterfaceDao;
import com.baiyang.server.model.system.JurisdictionInterface;
import com.baiyang.server.service.impl.BaseServiceImpl;
import com.baiyang.server.service.system.JurisdictionInterfaceService;

import java.util.*;

/**
 * 
 * @author XVX
 * BY: @Primary 注解帮助生命@Autowired优先注入的实列
 */
@Service	
public class JurisdictionInterfaceServiceImpl extends BaseServiceImpl<JurisdictionInterfaceDao, JurisdictionInterface>implements JurisdictionInterfaceService{
    @Autowired
    private JurisdictionInterfaceDao jurisdictionInterfaceDao = null;


    @Override
    public JSONObject getTree() {
        JurisdictionInterface jurisdictionInterface = new JurisdictionInterface();
        List<JurisdictionInterface> jurs = jurisdictionInterfaceDao.selectList(jurisdictionInterface);
        JSONObject tree = new JSONObject();
        jurs.forEach(e->{
            String group = e.getJurisdictionGroup();
            JSONObject item = new JSONObject();
            item.put("group",e.getJurisdictionGroup());
            item.put("url",e.getInterfaceUrl());
            item.put("id",e.getId());
            item.put("name",e.getJurisdiction());
            if(tree.getJSONArray(group) == null){
                JSONArray array = new JSONArray();
                array.add(item);
                tree.put(group,array);
            }else{
                JSONArray array = tree.getJSONArray(group);
                array.add(item);
            }
        });
        return tree;
    }
}
